﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using MINERP.BLL;
using MINERP.BLL.MobileMsgSend;
using MINERP.MODEL.FoundationModel;
using MINERP.MODEL.MobileMsgSend;

namespace MINERP.MobileMsgSend.Forms
{
    public partial class FrmShopInfo : Form
    {
        public FrmShopInfo(List<TelList> inList)
        {
            InitializeComponent();
            NowList = inList;
        }
        
        
        private void simpleButtonFan_Click(object sender, EventArgs e)
        {
            int aCount = gridViewShop.RowCount;
            for (int i = 0; i < aCount; i++)
            {
                Shop_Info info = (Shop_Info)gridViewShop.GetRow(i);
                if (info.IsSelect)
                {
                    info.IsSelect = false;
                }
                else
                {
                    info.IsSelect = true;
                }
            }
            gridControlShop.RefreshDataSource();
        }

        private void simpleButtonAllSelect_Click(object sender, EventArgs e)
        {
            this.Text = gridViewShop.FilterPanelText;
            int aCount = gridViewShop.RowCount;
            for (int i = 0; i < aCount; i++)
            {
                Shop_Info info = (Shop_Info)gridViewShop.GetRow(i);
                info.IsSelect = true;
            }
            gridControlShop.RefreshDataSource();
        }

        private void FrmShopInfo_Load(object sender, EventArgs e)
        {
            List<Shop_Info> listShopInfo = _bll.GetShop();
           
            foreach (TelList strNow in NowList)
            {           
                Shop_Info info = listShopInfo.FirstOrDefault(p => p.Tel2 == strNow.Tel);
                if (info != null)
                {
                    info.IsSelect = true;
                }
                else
                {
                    NewList.Add(strNow);
                }
            }
            gridControlShop.DataSource = listShopInfo;
        }

        private void simpleButtonMark_Click(object sender, EventArgs e)
        {
            int aCount = gridViewShop.RowCount;
            for (int i = 0; i < aCount; i++)
            {
                Shop_Info info = (Shop_Info)gridViewShop.GetRow(i);
                if (info.IsSelect && !string.IsNullOrEmpty(info.Tel2) && info.Tel2.Trim().Length==11)
                {
                    NewList.Add(new TelList(){ SendTo=info.ShopName, Tel=info.Tel2.Trim()});
                }

            }
           PassTelList(NewList);
            this.Close();
        }
        private void gridViewShop_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
        {
            if (e.RowHandle >= 0)
            {
                Shop_Info info = (Shop_Info)gridViewShop.GetRow(e.RowHandle);
                if (!string.IsNullOrEmpty(info.Tel2) && info.Tel2.Trim().Length != 11)
                {
                    e.Appearance.BackColor = Color.Red;
                }
            }
        }

        public List<TelList> NowList = new List<TelList>();//已经有的列表 
        public List<TelList> NewList = new List<TelList>();//新的列表 
        private MobileMsgSendBLL _bll = new MobileMsgSendBLL();
        public  delegate void PassList(List<TelList> inList);
        public event PassList PassTelList;

        

      
    }
}
